﻿namespace _3_FactoryMethod;

public static class ShapeFactory
{
    private static readonly Random Random = new Random();

    private static double ShapeRandom()
    {
        return Random.Next(1, 100) *0.1;//产生边长，半径等数据，浮点数储存上可能会有精度问题，产生误差
    }

    public static Shape CreateRandomShape()
    {
        var type = Random.Next(1, 4);
        return type switch
        {
            1 => Rectangle.CreateInstance(ShapeRandom(),ShapeRandom()),
            2 => Circle.CreateInstance(ShapeRandom()),
            3 => Square.CreateInstance(ShapeRandom()),
            _ => throw new InvalidOperationException("Invalid")
        };
    }
}